const {app, BrowserWindow} = require("electron")
const path = require("path");
const WinState = require('electron-win-state').default

require("./ipcMain/getResources")

require("./ipcMain/alert")

require("./ipcMain/openWindow")

//创建主窗口
const createWindow = () => {

    const winState = new WinState({
        defaultWidth: 1000,
        defaultHeight: 800,
    })
    const win = new BrowserWindow({
        ...winState.winOptions,
        //预加载脚本
        webPreferences: {
            preload: path.resolve(__dirname, './preload/index.js')
        }
    })

    win.loadURL("http://127.0.0.1:5173");
    //管理窗口位置状态
    winState.manage(win)

    //开启调试工具
    win.webContents.openDevTools()
}

//应用准备就绪 创建主窗口
app.whenReady().then(() => {
    createWindow();
    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
})
//监听所有窗口关闭 并退出程序
app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit()
    }
})
